<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="javax.persistence.EntityTransaction,javax.persistence.EntityManagerFactory,javax.persistence.EntityManager" %>
<%@ page import="treqs.model.HibernateUtil,treqs.model.Requirement,treqs.model.Requirementpriority,treqs.model.Requirementstatus"%>
<%@ page import="java.util.List, java.util.Iterator" %>


    <table>
        <tr>
            <th></th>
            <th>UID</th>
			<th>name</th>
			<th>description</th>
			<th>rationale</th>
			<th>comment</th>
			<th>revision</th>
			<th>priorityID</th>
			<th>statusID</th>
			<th>creationDate</th>
			<th>deletionDate</th>
			<th>editDate</th>
			<th>editLog</th>
		</tr>

		<%
			try
			{			
				EntityManagerFactory emf = HibernateUtil.getEntityManagerFactory();
				EntityManager em = emf.createEntityManager();
				EntityTransaction tx = em.getTransaction();
				tx.begin();
		
				List requirements = 
					em.createQuery(
					"select requirement from Requirement as requirement")
			    .getResultList();
				Requirement requirement;
				for(Iterator itr = requirements.iterator(); itr.hasNext();)
				{
					requirement = (Requirement)itr.next();
					out.println("<tr>");
					out.println("<td>");
					out.println("<a href=\"manage.jsp?id=" + requirement.getId() + "\">Edit</a>");
					out.println(" | ");
					out.println("<a href=\"details.jsp?id=" + requirement.getId() + "\">Details</a>");
					out.println("</td>");
		            out.println("<td>" + requirement.getUid() + "</td>");
		            out.println("<td>" + requirement.getName() + "</td>");
		            out.println("<td>" + requirement.getDescription() + "</td>");
		            out.println("<td>" + requirement.getRationale() + "</td>");
		            out.println("<td>" + requirement.getComment() + "</td>");
		            out.println("<td>" + requirement.getRevision() + "</td>");
		            out.println("<td>" + requirement.getRequirementpriority().getValue() + "</td>");
		            out.println("<td>" + requirement.getRequirementstatus().getValue() + "</td>");
		            out.println("<td>" + requirement.getCreationDate() + "</td>");
		            out.println("<td>" + requirement.getDeletionDate() + "</td>");
		            out.println("<td>" + requirement.getEditDate() + "</td>");
		            out.println("<td>" + requirement.getEditLog() + "</td>");
					out.println("</tr>");
				}
				tx.commit();
				em.close();
			}
			catch (Exception ex)
			{
				out.println(ex.toString());
			}
		%>
    </table>

